<template>
    <h2>增加门店</h2>
    <table>
        <tr>
            <td>门店名称</td>
            <td>
                <input type="text" v-model="pirst.name">
            </td>
        </tr>
        <tr>
            <td>门店地址</td>
            <td>
                <input type="text" v-model="pirst.address">
            </td>
        </tr>
        <tr>
            <td>门店图片</td>
            <td>
                <input type="file" @change="mendiamege">
                <img :src="src" width="50" height="50" v-if="pirst.picture">
            </td>
        </tr>
        <tr>
            <td>修改时间</td>
            <td>
                <input type="date" v-model="pirst.xdate">
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="addsssom">
            </td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import {reactive, toRefs} from 'vue'
  import axios from 'axios'
  import {useRouter,useRoute} from 'vue-router'

  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    pirst:{
        name:'',
        address:'',
        picture:'',
        xdate:''
    },
    src:''
  })
  let {pirst,src} =toRefs(data)

  const mendiamege=(e:any)=>{
    var form=new FormData()
    var obj=e.target.files[0]
    form.append('file',obj)
    axios({
        url:'/api/Upfile/Upload',
        method:'post',
        data:form
    })
    .then(res=>{
        src.value='https://localhost:7104'+res.data.filename;
        pirst.value.picture=res.data.filename;
    })
  }

  const addsssom=()=>{
    let obj={
        "sname": pirst.value.name,
  "address": pirst.value.address,
  "spicture": pirst.value.picture,
  "sttts": 1,
  "supdtime": pirst.value.xdate,
  "isdelete": false
    }
    axios({
        url:'/api/Mem/Addstore',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data.data==1){
            alert("添加门店成功")
        }else{
            alert("添加门店失败")
        }
    })
  }
  </script>
  
  <style scoped>
  
  </style>